package com.podium.web.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.podium.auth.utils.SecurityUtils;
import com.podium.web.system.entity.SysDictType;
import com.podium.web.system.mapper.SysDictTypeMapper;
import com.podium.web.system.service.SysDictTypeService;
import com.podium.comment.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 邵文泽
 * @description 字典管理
 * @date 2025-05-09 15:33:44
 */
@Slf4j
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements SysDictTypeService {

    @Override
    public IPage<SysDictType> page(Page<SysDictType> page, SysDictType sysDictType) {
        QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SysDictType::getDelFlag, 0)
                .like(StringUtils.hasLength(sysDictType.getDictName()), SysDictType::getDictName, sysDictType.getDictName())
                .like(StringUtils.hasLength(sysDictType.getDictKey()), SysDictType::getDictKey, sysDictType.getDictKey())
        ;
        return super.page(page, queryWrapper);
    }

    @Override
    public List<SysDictType> list(SysDictType sysDictType) {
        QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SysDictType::getDelFlag, 0)
                .like(StringUtils.hasLength(sysDictType.getDictName()), SysDictType::getDictName, sysDictType.getDictName())
                .like(StringUtils.hasLength(sysDictType.getDictKey()), SysDictType::getDictKey, sysDictType.getDictKey())
        ;
        return super.list(queryWrapper);
    }

    @Override
    public SysDictType getById(Long id) {
        return super.getById(id);
    }

    @Override
    public boolean save(SysDictType sysDictType) {
        sysDictType.setDelFlag(0L);
        sysDictType.setCreateBy(SecurityUtils.getUsername());
        sysDictType.setCreateTime(LocalDateTime.now());
        return super.save(sysDictType);
    }

    @Override
    public boolean updateById(SysDictType sysDictType) {
        sysDictType.setUpdateBy(SecurityUtils.getUsername());
        sysDictType.setUpdateTime(LocalDateTime.now());
        return super.updateById(sysDictType);
    }

    @Override
    public void removeById(Long id) {
        super.removeById(id);
    }

    @Override
    public List<SysDictType> listByIds(List<Long> dictTypeIds) {
        return super.listByIds(dictTypeIds);
    }

}